package lincen.javame.light.ui.geometric;

import java.awt.Graphics;


/**
 * Բ
 * @author ���
 */
public class OvalFloat extends PointFloat {

	/**
	 * Բ�İ뾶
	 */
	private float r;

	public void setR(float r) {
		this.r = r;
	}

	public float getR() {
		return r;
	}
	/**
	 * ʵ���ж�����Բ�����о����Ƿ��໥��ײ, ������о��ζ�������, ��ô����Բһ����������ײ
	 * �������ܻ��ÿ���ж������߳��� ���ܸ��
	 * �ж�����Բ�Ƿ����л����ཻ
	 * @param oval
	 * @return
	 */
	public boolean isCollidesWith(OvalFloat oval){
		if(!isCollidesWithRect(oval)){
			return false;
		} else {
			if(
					MathUtil.hypot(this.getX() - oval.getX(), this.getY() - oval.getY()) <= 
						this.getR() + oval.getR()
			){
				return true;
			} else {
				return false;
			}
		}
	}

	/**
	 * �ж�����Բ�����о����Ƿ�����ײ
	 * @param oval
	 * @return
	 */
	private boolean isCollidesWithRect(OvalFloat oval) {
		return 
		!(
				this.getX()>=oval.getX() + oval.getR() * 2 ||
				this.getX() + this.getR() * 2 <= oval.getX()||
				this.getY()>=oval.getY() + oval.getR() * 2||
				this.getY() + this.getR() * 2 <= oval.getY()
		);
	}
	
	public void paint(Graphics g) {
		g.fillArc(
				(int)(this.getX() - this.getR()), 
				(int)(this.getY() - this.getR()), 
				(int)(this.getR() * 2), 
				(int)(this.getR() * 2), 
				0, 
				360
		);
	}
}
